// 云函数入口文件
const cloud = require('wx-server-sdk')
var rp = require('request-promise');

let appid = 'wx048f059ad7a571b7'
let secret = 'bb37b8cadefb031976ee63a768377619'
let msgCheckUrl = 'https://api.weixin.qq.com/sns/jscode2session?appid=' //请求接口的链接
let tokenUrl = msgCheckUrl + appid + '&secret=' + secret //API入口凭证
cloud.init()//初始化
// 云函数入口函数
exports.main = async (event, context) => {
  let url = tokenUrl + '&js_code=' + event.code + '&grant_type=authorization_code'
  return await rp(url)
    .then(function (res){
      return res
    })
    .catch(function (err){
      return err
    })
} 